$(function () {
    $('#btn_search').click(function(){
        window.location.href= 'index.html?name=' + $('#hotelName').val();
    });

    $("input[id='requestEditEnddate']").datepicker({
        format: 'yyyy-mm-dd',
        language: "zh-CN",
        autoclose: true
    });
    
    $(".edit").on('click', function (e,obj) {
        e.preventDefault();
        $("#editModel").data('id', $(this).attr('data-id'));
        $('#requestEditHotel').val($(this).attr('data-hotelName'));
        $('#requestEditEnddate').val($(this).attr('data-endDate'));
        if( $(this).attr('data-appStatus')==true ){
            $('#requestEditStatus_on').attr("checked",true);
        }else{
            $('#requestEditStatus_off').attr("checked",true);
        }
        $('#saveInfo').html('');
        $("#editModel").modal();
    });
    
    $('#requestEdit').click(function(){
        var param = {};
        param.hotelId = $("#editModel").data('id');
        if($("input[type='radio']:checked").val()==true){
            param.status = 1;
            if($('#requestEditEnddate').val()==''){
                $('#saveInfo').html('到期时间不能为空！');
                return false;
            }
        }else{
            param.status = 0;
        }
        param.endData = $('#requestEditEnddate').val();
        $.post("edit.html", param, function(result){
            if(result.status==200){
                window.location.href=window.location.href;
            }else{
                $('#saveInfo').html('服务器繁忙！');
            }
        });
        return false;
    });
});